package com.victor.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.victor.entity.Messageboard;
import com.victor.service.MessageboardService;
import com.victor.utils.Msg;

/**
 * 留言板管理
 * 
 * @author Mr.Zhang
 *
 */
@RestController
@RequestMapping("/messageboard")
public class MessageboardController {

	@Autowired
	private MessageboardService service;

	// 新建留言
	@RequestMapping("/build")
	public Msg build(Messageboard messageboard) {
		boolean insResult = service.build(messageboard);
		return insResult ? Msg.success() : Msg.fail();
	}

	// 查询所有留言
	@RequestMapping("getAll")
	public Msg getAll() {
		List<Messageboard> messageboards = service.getAll();
		return Msg.success().add("messageboards", messageboards);
	}

	// 批量删除留言
	@RequestMapping("batchDelete")
	public Msg batchDelete(int[] ids) {
		boolean delResult = service.batchDelete(ids);
		return delResult ? Msg.success() : Msg.fail();
	}
}
